#include <unistd.h>
#include <limits>
#include <iostream>

using namespace std;

void printStreamStatus(std::istream & is){ 
    cout << "is's goodbit:" << is.good() << endl;
    cout << "is's badbit:" << is.bad() << endl;
    cout << "is's failbit:" << is.fail() << endl;
    cout << "is's eofbit:" << is.eof() << endl;
}

void test0(){
    printStreamStatus(cin);  //goodbit status
    int num = 0;    
    cin >> num;   
    cout << "num:" << num << endl;
    printStreamStatus(cin);  //take once input than check cin status
}

void test1()
{
    if(!cin.good()){
        //recover steam status
        cin.clear();
        //clean buffer than can use
        cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
        cout << endl;
        printStreamStatus(cin);
    }
}

void testBuffer()
{
    //buffer is full
    for(int i = 0; i < 1025; ++i)
    {
        cout << "a";
    }
    sleep(2);

    //endl operator to reflash buffer
    for(int i = 0; i < 1025; ++i)
    {
        cout << "a" << endl;
    }

    sleep(2);
}

void testError()
{
    cerr << 1;
    cerr << 3;
    sleep(2);
}

int main()
{
    test0();
    test1();
    testBuffer();
    return 0;
}

